fix: [#2052] Correct caption element content model to allow flow content#2058
Merged
capricorn86 merged 1 commit intoFeb 9, 2026
Merged
Conversation
22e636a to
614b105
Compare
…w flow content Fixes capricorn86#2052 ## Problem The caption element was incorrectly configured with contentModel: textOrComments, which only allowed text nodes and comments. Per the HTML spec, caption elements should contain flow content (inline and block elements), except table elements. This caused elements like <b>, <em>, <span>, etc. to be incorrectly moved outside the caption during parsing. ## Changes ### packages/happy-dom/src/config/HTMLElementConfig.ts Updated caption element configuration to match the HTML spec and follow the same pattern as td/th elements: - Changed contentModel from textOrComments to noForbiddenFirstLevelDescendants - Added forbiddenDescendants: table structure elements (table, tbody, thead, tfoot, tr, td, th, col, colgroup) - Added permittedParents: ['table'] to ensure caption only appears in tables ### packages/happy-dom/test/html-parser/HTMLParser.malformedHTML.test.ts Added comprehensive test coverage for caption element content model: - Inline elements preservation (b, strong, em, span, a) - Nested inline elements - Block-level elements (p, div) - Table element prohibition - Content serialization - permittedParents validation (wrong parent, standalone, correct parent) ## Implementation Details This fix follows the same pattern as PR capricorn86#2007 for paragraph elements, using the existing noForbiddenFirstLevelDescendants content model. While this doesn't recursively check deeply nested table elements, it matches the existing codebase patterns and handles the vast majority of real-world cases.
e9ef366 to
639c2d8
Compare
Contributor
Author
|
Was this done an LLM? Who on earth writes such pull request descriptions? |
Contributor
Author
|
I did use an LLM as a writing aid and reviewed the content myself. Please let me know if you have any feedback on the actual changes👋 |
capricorn86
approved these changes
Feb 9, 2026
Owner
capricorn86
left a comment
There was a problem hiding this comment.
Thank you for your contribution @atzzCokeK! :star
RAprogramm
pushed a commit
to RAprogramm/fork-happy-dom
that referenced
this pull request
Feb 20, 2026
…w flow content (capricorn86#2058) Fixes capricorn86#2052 ## Problem The caption element was incorrectly configured with contentModel: textOrComments, which only allowed text nodes and comments. Per the HTML spec, caption elements should contain flow content (inline and block elements), except table elements. This caused elements like <b>, <em>, <span>, etc. to be incorrectly moved outside the caption during parsing. ## Changes ### packages/happy-dom/src/config/HTMLElementConfig.ts Updated caption element configuration to match the HTML spec and follow the same pattern as td/th elements: - Changed contentModel from textOrComments to noForbiddenFirstLevelDescendants - Added forbiddenDescendants: table structure elements (table, tbody, thead, tfoot, tr, td, th, col, colgroup) - Added permittedParents: ['table'] to ensure caption only appears in tables ### packages/happy-dom/test/html-parser/HTMLParser.malformedHTML.test.ts Added comprehensive test coverage for caption element content model: - Inline elements preservation (b, strong, em, span, a) - Nested inline elements - Block-level elements (p, div) - Table element prohibition - Content serialization - permittedParents validation (wrong parent, standalone, correct parent) ## Implementation Details This fix follows the same pattern as PR capricorn86#2007 for paragraph elements, using the existing noForbiddenFirstLevelDescendants content model. While this doesn't recursively check deeply nested table elements, it matches the existing codebase patterns and handles the vast majority of real-world cases.
RAprogramm
pushed a commit
to RAprogramm/fork-happy-dom
that referenced
this pull request
Feb 20, 2026
…w flow content (capricorn86#2058) Fixes capricorn86#2052 ## Problem The caption element was incorrectly configured with contentModel: textOrComments, which only allowed text nodes and comments. Per the HTML spec, caption elements should contain flow content (inline and block elements), except table elements. This caused elements like <b>, <em>, <span>, etc. to be incorrectly moved outside the caption during parsing. ## Changes ### packages/happy-dom/src/config/HTMLElementConfig.ts Updated caption element configuration to match the HTML spec and follow the same pattern as td/th elements: - Changed contentModel from textOrComments to noForbiddenFirstLevelDescendants - Added forbiddenDescendants: table structure elements (table, tbody, thead, tfoot, tr, td, th, col, colgroup) - Added permittedParents: ['table'] to ensure caption only appears in tables ### packages/happy-dom/test/html-parser/HTMLParser.malformedHTML.test.ts Added comprehensive test coverage for caption element content model: - Inline elements preservation (b, strong, em, span, a) - Nested inline elements - Block-level elements (p, div) - Table element prohibition - Content serialization - permittedParents validation (wrong parent, standalone, correct parent) ## Implementation Details This fix follows the same pattern as PR capricorn86#2007 for paragraph elements, using the existing noForbiddenFirstLevelDescendants content model. While this doesn't recursively check deeply nested table elements, it matches the existing codebase patterns and handles the vast majority of real-world cases.
capricorn86
added a commit
that referenced
this pull request
Jun 2, 2026
* fix: [#2035] Updates README.md for the server-renderer package (#2037) * feat: [#241] Add canvas adapter pattern for pluggable rendering support Adds ICanvasAdapter interface and static setCanvasAdapter() method to HTMLCanvasElement, allowing users to plug in real canvas implementations like node-canvas. Changes: - Add ICanvasAdapter interface with getContext(), toDataURL(), toBlob() methods - Add HTMLCanvasElement.setCanvasAdapter() and getCanvasAdapter() static methods - Delegate canvas operations to adapter when set - Add NodeCanvasAdapter implementation using node-canvas library - Add comprehensive tests (44 new tests) This enables real canvas rendering in Happy-DOM when node-canvas is installed: ```typescript import { HTMLCanvasElement } from 'happy-dom'; import { NodeCanvasAdapter } from 'happy-dom/lib/nodes/html-canvas-element/adapters/NodeCanvasAdapter.js'; HTMLCanvasElement.setCanvasAdapter(new NodeCanvasAdapter()); // Now canvas.getContext('2d') returns real CanvasRenderingContext2D ``` Closes #241 * fix: [#241] Fix linting errors and code style - Fix member ordering in HTMLCanvasElement class - Add curly braces to all if statements - Add public access modifiers to methods - Add JSDoc comments for all parameters - Use angle bracket type assertions in tests - Fix code formatting per project standards * fix: [#1850] Selection API focusNode and focusOffset returning incorrect values (#1953) - Fixed focusNode getter to return the correct focus boundary point based on selection direction - Fixed focusOffset getter to return the correct focus offset based on selection direction * fix: [#1952] Accept Document nodes as valid boundary points in Selection API (#1954) * feat: [#2049] Adds support for caching the compiled code of EcmaScript modules (#2050) * feat: [#2049] Adds support for caching the compiled code of EcmaScript modules * feat: [#2049] Adds support for caching the compiled code of EcmaScript modules * feat: [#2049] Adds support for caching the compiled code of EcmaScript modules * feat: [#2055] Changes internal types to follow a consistent pattern (#2056) * fix: [#1955] Fixes stepUp and stepDown on HTMLInputElement according to spec (#1960) * fix: [#1955] Conforming stepUp and stepDown on HTMLInputElement to spec for number inputs * chore: [#1960] Fixes implementation to follow the spec and the project coding style * chore: [#1960] Fixes implementation to follow the spec and the project coding style --------- * fix: [#1947] Use entities package for HTML/XML encoding/decoding (#2016) - Replace decodeHTMLAttributeValue with entities.decodeHTMLAttribute - Replace decodeHTMLEntities with entities.decodeHTML - Replace decodeXMLAttributeValue with entities.decodeXML - Replace decodeXMLEntities with entities.decodeXML - Replace encodeTextContent with entities.escapeText - Add entities@6 as dependency - Remove unused regex patterns and lookup tables - Add test for numeric character reference decoding in attributes This fixes issue #1947 where numeric character references like " and " were not being decoded in HTML attribute values. * chore: [#1947] Adds unit tests for decode ' / numeric character references in attr values (#1948) - attribute values can contain named and numeric character references per https://html.spec.whatwg.org/multipage/syntax.html#syntax-attribute-value - add decoding for all numeric character references - add decoding for ', this could probably appear in single-quoted attribute values - ignore other named character references, the list is huge * fix: Node.replaceWith does not throw w/o parent (#1969) * fix: Node.replaceWith does not throw w/o parent ```js let div = document.createElement("div"); let span = document.createElement("span"); div.parentNode; // null span.parentNode; // null div.replaceWith(span); // ok ``` * chore: remove unused DOMException import * chore: [#0] Adds unit test --------- * fix: [#1959] Implement Text.wholeText property (#2027) * fix: [#1959] Implement Text.wholeText property * fix: [#1959] Implement Text.wholeText property --------- * fix: [#2052] Correct caption element content model to allow flow content (#2058) Fixes #2052 ## Problem The caption element was incorrectly configured with contentModel: textOrComments, which only allowed text nodes and comments. Per the HTML spec, caption elements should contain flow content (inline and block elements), except table elements. This caused elements like <b>, <em>, <span>, etc. to be incorrectly moved outside the caption during parsing. ## Changes ### packages/happy-dom/src/config/HTMLElementConfig.ts Updated caption element configuration to match the HTML spec and follow the same pattern as td/th elements: - Changed contentModel from textOrComments to noForbiddenFirstLevelDescendants - Added forbiddenDescendants: table structure elements (table, tbody, thead, tfoot, tr, td, th, col, colgroup) - Added permittedParents: ['table'] to ensure caption only appears in tables ### packages/happy-dom/test/html-parser/HTMLParser.malformedHTML.test.ts Added comprehensive test coverage for caption element content model: - Inline elements preservation (b, strong, em, span, a) - Nested inline elements - Block-level elements (p, div) - Table element prohibition - Content serialization - permittedParents validation (wrong parent, standalone, correct parent) ## Implementation Details This fix follows the same pattern as PR #2007 for paragraph elements, using the existing noForbiddenFirstLevelDescendants content model. While this doesn't recursively check deeply nested table elements, it matches the existing codebase patterns and handles the vast majority of real-world cases. * feat: [#2060] Adds support for register on import in global-registrator (#2061) * fix: [#2057] Support Unicode characters in selectors per CSS spec (#2062) * fix: [#2057] Support Unicode characters in selectors per CSS spec The CSS specification allows identifiers (class names, IDs, element names) to contain ISO 10646 characters U+00A0 and higher. The regex patterns in SelectorParser.ts were only allowing ASCII characters plus a hardcoded workaround for guillemets. This change updates both SELECTOR_REGEXP and SIMPLE_SELECTOR_REGEXP to accept characters in the range \u00A0-\uFFFF, which covers Greek letters, CJK characters, Cyrillic, Arabic, Hebrew, and other Unicode scripts. * chore: [#2057] Adds unit tests * chore: [#2057] Adds unit tests --------- * fix: [#2042] Support CSS gradients with rgba() colors (#2059) * fix: [#2042] Support CSS gradients with rgba() colors This fix resolves an issue where CSS background properties containing linear gradients with rgba() color values would return empty strings. Root Cause: - GRADIENT_REGEXP pattern used [^)]+ which stopped at the first closing parenthesis, failing to match gradients with nested rgba() functions - String splitting logic didn't respect nested parentheses, incorrectly splitting rgba(0, 0, 0, 0) into multiple invalid parts Solution: - Updated GRADIENT_REGEXP to handle one level of nested parentheses - Improved getGradient() to split commas while respecting parentheses depth - Added splitByComma() and splitBySpace() helper functions to properly handle nested parentheses when parsing CSS values - Updated getBackground() and getBackgroundImage() to use new helpers Tests: - Added 15 comprehensive test cases covering rgba(), hsla(), rgb(), hsl() - Tests include repeating gradients, conic gradients, multiple gradients - Tests verify edge cases: many color stops, decimal values, whitespace - All 7,184 tests pass chore: [#2042] Format test file * fix: [#2042] Improves performance on splitting * fix: [#2042] Improves performance on splitting * fix: [#2042] Improves performance on splitting --------- * fix: [#2066] Update entities package version to resolve missing export for vue and vue-compat v3.5 (#2067) * fix: [#1910] Fixes issue when parsing complex query selector with has expression (#2068) * fix: [#1910] Fixes issue when parsing complex CSS has expression * fix: [#1910] Fixes issue when parsing complex CSS has expression * fix: [#1910] Fixes issue when parsing complex CSS has expression * feat: [#241] Refactor canvas adapter to use browser settings * feat: [#241] Fix `index.ts` missing import * feat: [#241] Add tests and documentation for node-canvas-adapter - Add 13 comprehensive tests for CanvasAdapter - Add .gitignore and .npmignore files - Enhance README.md with usage examples and API documentation - Update package.json with scripts, keywords and complete metadata - Update tsconfig.json with additional compiler options - Add canvas documentation to happy-dom README * feat: [#241] Update `package-json.lock` * feat: [#241] Add canvas adapter pattern for pluggable rendering support * feat: [#241] Canvas. Fix imports and callback sig * feat: [#241] Skip canvas tests if canvas not exists * feat: [#241] Add missing field to mocks * chore: [#0] Continues on implementation * chore: [#0] Continues on implementation * chore: [#0] Continues on implementation * chore: [#0] Continues on implementation * chore: [#0] Continues on implementation * chore: [#0] Continues on implementation * chore: [#0] Continues on implementation * chore: [#0] Continues on implementation * chore: [#0] Continues on implementation * chore: [#0] Continues on implementation * chore: [#0] Continues on implementation * chore: [#0] Continues on implementation --------- Co-authored-by: David Ortner <david@ortner.se> Co-authored-by: Sergey Kochetkov <skoch13@icloud.com> Co-authored-by: Steve Matney <steve.matney@gmail.com> Co-authored-by: Trevor Burnham <trevorburnham@gmail.com> Co-authored-by: cgoetz-inovex <carlo.goetz@inovex.de> Co-authored-by: Luke Edwards <lukeed@github.com> Co-authored-by: TAKAGI AKIHIRO <156570014+aki05162525@users.noreply.github.com> Co-authored-by: Atsushi Kawamura (atzz/a2c) <atsushi1230.sdi@gmail.com> Co-authored-by: Kai Gritun <kaigritun@gmail.com> Co-authored-by: Anthony Collins <acollins1991@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2052
Problem
The
<caption>element was incorrectly configured withcontentModel: textOrComments, which only allowed text nodes and comments as children. According to the HTML specification, caption elements should contain flow content (including inline and block elements), except table elements.This caused inline elements like
<b>,<em>,<span>, etc. to be incorrectly moved outside the caption during HTML parsing, resulting in broken DOM structures.Reproduction
Changes
packages/happy-dom/src/config/HTMLElementConfig.tsUpdated the
captionelement configuration to follow the HTML spec and match the pattern used by other table elements (td,th):Changes explained:
contentModel: Changed fromtextOrCommentstonoForbiddenFirstLevelDescendantsto allow flow contentforbiddenDescendants: Added table structure elements (per HTML spec: "Flow content, but with no descendant table elements")permittedParents: Added['table']to ensure caption only appears as a child of table elementspackages/happy-dom/test/html-parser/HTMLParser.malformedHTML.test.tsAdded comprehensive test coverage (9 new tests) for the caption element content model:
<b>,<strong>,<em>,<span>,<a>are correctly preserved inside caption<small><b>text</b></small>work correctly<p>and<div>are allowed (flow content)<table>elements inside caption are correctly moved outside<table>or when used standaloneImplementation Details
This implementation follows the same pattern as PR #2007 (paragraph elements), using the existing
noForbiddenFirstLevelDescendantscontent model. While this approach doesn't recursively check for deeply nested table elements (e.g.,<caption><div><table>...</table></div></caption>), it:forbiddenDescendantsandpermittedParentsTest Coverage
All tests pass:
Full test suite: